package com.jjh.dao.impl;

import com.jjh.pojo.User;
import com.jjh.winterframework.annatation.Component;
import com.jjh.consts.Properties;
import com.jjh.dao.OrderDao;
import com.jjh.pojo.Order;
import com.jjh.util.FileUtils;
import com.jjh.wrapper.QueryWrapper;

import java.util.ArrayList;
import java.util.List;
@Component
public class OrderDaoImpl implements OrderDao {


    @Override
    public boolean insertOne(Order order) {
        boolean b = FileUtils.ListToFile(List.of(order), Properties.ORDER_PATH, Order.class);
        return b;
    }

    /**
     * 根据用户id获取该用户下的订单
     * @param id
     * @return
     */
    @Override
    public List<Order> getOrdersByUsrId(int id) {



        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("userId",String.valueOf(id));

        List<Object>  objects = FileUtils.pageQueryList(1, 10, Properties.ORDER_PATH, Order.class, wrapper);


        List<Order> list = new ArrayList<>();

        for (Object obj : objects) {
            Order order = (Order) obj;
            list.add(order);
        }



      return list;
    }
}
